package se.djupfeldt.oscar.logbook.logging;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import se.djupfeldt.oscar.logbook.Logbook;

public class FileLogger {
    private String name;
    
    private FileWriter writer;
    
    public FileLogger(String name) throws IOException {
	this.name = name;
	String logLocation = Logbook.properties.getProperty("logPosition", "logs");
	File loc = new File(logLocation + "/" + this.name + "/");
	if (!loc.exists())
	    loc.mkdirs();
	writer = new FileWriter(logLocation + "/" + this.name + "/" + this.name + "_" + Logbook.getCurrentDateString() + ".txt");
    }
    
    public void log(Object item) throws IOException {
	writer.append(item.toString());
	writer.append("\n");
	writer.flush();
    }
    
    public void close() throws IOException {
	writer.close();
    }
}
